<?php



/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Game
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
 
class Game_Form_Search extends Fields_Form_Search
{
  protected $_fieldType = 'game';
  
  public function init()
  {
    parent::init();

    $this->loadDefaultDecorators();

    $this
      ->setAttribs(array(
        'id' => 'filter_form',
        'class' => 'games_browse_filters field_search_criteria',
      ))
      ->getDecorator('HtmlTag')
        ->setOption('class', 'browsegames_criteria games_browse_filters');
    

    // Add custom elements
    $this->getAdditionalOptionsElement();
    
  }

  public function getAdditionalOptionsElement()
  {
    $i = -5000;
    
    $this->addElement('Hidden', 'page', array(
      'order' => $i++,
    ));
    
    $this->addElement('Hidden', 'tag', array(
      'order' => $i++,
    ));    
    
    $this->addElement('Hidden', 'user', array(
      'order' => $i++,
    ));
    
    $this->addElement('Text', 'keyword', array(
      'label' => 'Keywords',
      'order' => $i++,
      'decorators' => array(
        'ViewHelper',
        array('Label', array('tag' => 'span')),
        array('HtmlTag', array('tag' => 'li'))
      ),
    ));     

    $categories_prepared = Engine_Api::_()->getItemTable('game_category')->getMultiOptionsAssoc();
    $categories_prepared = array(""=>"") + $categories_prepared;
    
    $this->addElement('Select', 'category', array(
      'label' => 'Category',
      'multiOptions' => $categories_prepared,
      'order' => $i++,
      'decorators' => array(
        'ViewHelper',
        array('Label', array('tag' => 'span')),
        array('HtmlTag', array('tag' => 'li'))
      ),
    ));     

    $this->addElement('Select', 'content_rating', array(
      'label' => 'Rating',
      'multiOptions' => array(""=>"") + Game_Form_Helper::getContentRatings(),
      'order' => $i++,
      'decorators' => array(
        'ViewHelper',
        array('Label', array('tag' => 'span')),
        array('HtmlTag', array('tag' => 'li'))
      ),
    )); 

    
    /*
    $this->addElement('Select', 'view', array(
      'label' => 'View:',
      'multiOptions' => array(
        '' => "Everyone's Games",
        '1' => "Only My Friends' Games",
      ),
      'order' => $i++,
      'decorators' => array(
        'ViewHelper',
        array('Label', array('tag' => 'span')),
        array('HtmlTag', array('tag' => 'li'))
      ),
    ));     
    */
    
    $this->addElement('Select', 'order', array(
      'label' => 'Sort By',
      'multiOptions' => array('' => '') + Game_Form_Helper::getOrders(),
      'order' => $i++,
      'decorators' => array(
        'ViewHelper',
        array('Label', array('tag' => 'span')),
        array('HtmlTag', array('tag' => 'li'))
      ),
    ));

    $this->addElement('Checkbox', 'leaderboard_enabled', array(
      'label' => 'Leaderboard Supported Games',
      'value' => 1,
      //'multiOptions' => array(""=>"") + Game_Form_Helper::getContentRatings(),
      'order' => $i++,
          'decorators' => array(
            'ViewHelper',
            array('Label', array('placement' => 'APPEND', 'tag' => 'label')),
            array('HtmlTag', array('tag' => 'li'))
          ),
    ));
    /*
    $seperator1 = $this->getElement('separator1');
    $this->removeElement('separator1');
    $seperator1->setOrder($i++);
    $this->addElement($seperator1);
		*/
    if (count($this->_fieldElements)) {
      $this->_order['separator1'] = $i++;
    }
    else {
      $this->removeElement('separator1');
    }
    
    $j = 10000000;  
    
    $this->addElement('Button', 'done', array(
      'label' => 'Search',
      'type' => 'submit',
      'ignore' => true,
      'order' => $j++,
      'decorators' => array(
        'ViewHelper',
        array('HtmlTag', array('tag' => 'li'))
      ),
    ));
  }
  
}